#ifndef LOG_UTILS__H
#define LOG_UTILS__H

#include <stdio.h>
#include <stdbool.h>

#include "common.h"

# ifdef __cplusplus
extern "C" {
# endif

// define for enbedded system
#define FILE_MAX_SIZE 2000000 // 2M bytes/file
typedef struct loger {
	FILE *fp;
    char path[FILE_PATH_LENGTH];
    char filename[FILE_NAME_LENGTH];
    int  fileNumber;
    bool initState;
    int filesize;
} loger_t;

#define LOG_LEVEL  7

#define LOG_EMERG   0   /* system is unusable */
#define LOG_ALERT   1   /* action must be taken immediately */
#define LOG_CRIT    2   /* critical conditions */
#define LOG_ERR     3   /* error conditions */
#define LOG_WARNING 4   /* warning conditions */
#define LOG_NOTICE  5   /* normal but significant condition */
#define LOG_INFO    6   /* informational */
#define LOG_DEBUG   7   /* debug-level messages */

int log_msg(loger_t* loger, int priority, char* logmsg, ...);
#define log_info(loger, logmsg, args...)  log_msg(loger, LOG_INFO, logmsg, ##args)
#define log_debug(loger, logmsg, args...) log_msg(loger, LOG_DEBUG, logmsg, ##args)
#define log_warn(loger, logmsg, args...)  log_msg(loger, LOG_WARNING, logmsg, ##args)
#define log_error(loger, logmsg, args...) log_msg(loger, LOG_ERR, logmsg, ##args)
#define log_alert(loger, logmsg, args...) log_msg(loger, LOG_ALERT, logmsg, ##args)

loger_t* log_init(char* filename, int number, char* path);
void log_close(loger_t* loger);
void log_clear(loger_t* loger);
void log_startBackup(const char* path);
void log_cancelBackup();

# ifdef __cplusplus
}
#endif

#endif // LOG_UTILS_H
